<?php

namespace App\Observers;

use App\Models\Pictuer;
use App\Jobs\GetPictuerAverageJobs;

// creating, created, updating, updated, saving,
// saved,  deleting, deleted, restoring, restored

class PictuerObserver
{

    public function saved(Pictuer $pictuer)
    {
        if (!$pictuer->title && $crawler = \App\Models\CrawlerPictuer::with('article')->find($pictuer->crawler_pictuer_id))
        {
            $pictuer->title = $crawler->article->title;
        }

    }
    public function created(Pictuer $pictuer)
    {
      if (!$pictuer->rgb || $pictuer->color_average_id == 0) {
        dispatch(new GetPictuerAverageJobs([['id' => $pictuer->id, 'path' => $pictuer->path, 'filename' => $pictuer->filename]]));
      }
    }
    public function updating(Pictuer $pictuer)
    {
        //
    }
}
